package logic

import (
	"context"
	"house_srv/models/mysql"

	"house_srv/house"
	"house_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type HouseListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewHouseListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HouseListLogic {
	return &HouseListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *HouseListLogic) HouseList(in *house.HouseListRequest) (*house.HouseListResponse, error) {
	// todo: add your logic here and delete this line
	var h []mysql.House
	err := mysql.Db.Where("house_status = 2 or house_examine = 2", in.HouseStatus, in.HouseExamine).Find(&h).Error
	if err != nil {
		logx.Info("房源列表错误", err)
	}
	var slice []*house.HouseList
	for _, v := range h {
		list := house.HouseList{
			HouseName:  v.HouseName,
			Address:    v.Address,
			HouseType:  v.HouseType,
			HouseFloor: v.HouseFloor,
			Price:      v.Price,
			HouseArea:  v.HouseArea,
			HouseCover: v.HouseCover,
			HouseId:    int64(v.ID),
		}
		slice = append(slice, &list)
	}
	return &house.HouseListResponse{
		List: slice,
	}, nil
}
